<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录</title>
    <link rel="stylesheet" href="css/login.css"/>
</head>
<body>
<div class="container">
    <div id="login_box">
        <form id="login_form">
            <div class="form-group">
                <div class="user"><img src="img/login/user.png"/></div>
                <input type="text" placeholder="请输入账号" id="username" name="username"/>
            </div>
            <div class="form-group">
                <div class="secret"><img src="img/login/password.png"/></div>
                <input type="password" placeholder="请输入密码" id="password" name="password"/>
            </div>
            <div class="form-group">
                <input type="text" placeholder="请输入验证码" id="identify_code" name="code"/>
                <div class="get_code" onclick="getCode();">
                
                </div>
                
            </div>
            <div id="msg" style="color:#333;height:30px;"></div>
            <button type="button" id="btn">登录</button>
        </form>
    </div>
</div>
<script src="js/jquery-1.12.4.js"></script>
<script src="js/url.js"></script>
<script>
    $("#btn").click(function () {
        login();
    });
    function login(){
        var username = $("#username").val();
        var password = $("#password").val();
        var code=$('#identify_code').val();
        if (username == "" || username.length < 1) {
            $("#msg").html("请输入至少一位的用户名");
            return false;
        }
        ;
        if (password == "" || password.length < 2) {
            $("#msg").html("请输入至少两位的密码");
            return false;
        }
        $.ajax({
            url: mainUrl + '/user/login',
            type: 'post',
            dataType: 'json',
            data: {"user.username": username, "user.password": password,"code":code},
            success: function (data) {
                $("#msg").html(data.errMsg).css('font-size','16px');
                /* sessionStorage.setItem('user.username', data.data.username);
                sessionStorage.setItem('user.showname', data.data.name);
                sessionStorage.setItem('perKeys', data.data.perKeys); */
                if (0 == data.errCode) {
                	alert("login success");
//                     window.location.href = "main.html";
                }
                if(-1 == data.errCode){
                    $("#msg").html(data.errMsg);
                }
                /* var orderId =  sessionStorage.getItem('orderId');
                   sessionStorage.usetItem('orderId', data.data.ID); */
            }

        });
    }
    $(document).keydown(function(e){
        if (event.keyCode == 13){
            login();
        }
    });
    function getCode() {
        $('.get_code').empty();
        var img = '<img src="' + mainUrl + '/user/getCode?a='+Math.random()+'"/>';
        $('.get_code').append(img);
    }
    getCode();
    $('.container').css('height',$(window).height());
</script>
</body>
</html>